import { WorldUIPool } from '../etc/UIPool';

export const PlayerHeadUIPool: WorldUIPool<PlayerHeadUI> = new WorldUIPool(() => { return new PlayerHeadUI(); });
export class PlayerHeadUI {
    uiWidget: mw.UIWidget;
    stage: boolean;
    targetCharacter: Character;

    txt_name: mw.TextBlock;

    constructor() {
        this.uiWidget = GameObject.spawn('UIWidget', { replicates: false });
        this.uiWidget.setUIbyID('C13E19574DD01D16CFBCDAB5A679AF3E');
        this.uiWidget.widgetSpace = WidgetSpaceMode.OverheadUI;
        this.uiWidget.occlusionEnable = false;
        this.uiWidget.hideByDistanceEnable = false;
        this.txt_name = <mw.TextBlock>this.uiWidget.getTargetUIWidget().rootContent.getChildByName('txt_name');
    }

    setInfo(player: Character, name: string) {
        this.targetCharacter = player;
        player.attachToSlot(this.uiWidget, HumanoidSlotType.Root);
        this.txt_name.text = name;
        if (!this.uiWidget.localTransform) return;
        this.uiWidget.localTransform.position = new Vector(0, 0, 230);
    }
}
